package stream.order;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/**
 * java.lang.Comparable接口是燃对象拥有能排序的能力
 * java.util.Comparator 提供默认的排序方法
 * java.util.Comparators 提供了自然排顺序和非空排序
 * naturalOrder 自然排序
 * reversed 反向排序
 * default Comparator<T> thenComparing(Comparator<? super T> other)
 * 用于有重复元素的情况下再用thenComparing方法指定的排序
 *
 * default <U> Comparator<T> thenComparing(Function<? super T, ? extends U> keyExtractor,
 *             Comparator<? super U> keyComparator)
 * 通过提取的属性排序，keyExtractor是提取方法
 */
public class OrderDemo {

    //比较接口
    public static void main(String[] args) {
        Comparable<String> sort = new java.lang.Comparable<String>(){
            @Override
            public int compareTo(String o) {
                return this.compareTo(o);
            }
        };
        Comparator<String> sortor = new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.compareTo(o2);
            }
        };
        List<String> list = Arrays.asList("1", "2","3");
        list.sort(sortor.reversed().thenComparing(sortor));
        System.out.println(list);
    }
}
